package com.itheima.extends5override;

public class Test2 {
    //目标：方法重写的常见应用场景，子类重写Object的toString方法，以便返回对象的内容
    public static void main(String[] args) {
        Student s= new Student("赵敏",'女',25);
        //System.out.println(s.toString());     toString可省略

        System.out.println(s);      //打印的是地址com.itheima.extends5override.Student@b4c966a
        //注意1:直接输出对象,默认会调用Object的toString方法(可省略不写),返回对象的地址信息
        //注意2:输出对象的地址实际上没有什么意义,更希望看到对象的内容信息.所以子类需要重写Object的toString方法,
        //      以便以后输出对象时默认就近调了用子类重写的toString方法返回对象的内容
    }
}

class Student extends Object{
    private String name;
    private char sex;
    private int age;

    @Override
    public String toString() {      //右键生成里有toString方法
        return "Student{" +
                "name='" + name + '\'' +
                ", sex=" + sex +
                ", age=" + age +
                '}';
    }

    public Student() {
    }

    public Student(String name, char sex, int age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }


}
